#coding:utf-8

import report
import buss
from protocols import Protocol4101,Protocol4110,Protocol4141,Protocol4150
import protocols
import wx
import sys
textCheckPoint = \
u"""
shoujiji
asdjklsdfglkj
asdjkfdg
sdfas
"""

import wx
class Window(wx.PyWindow):
    def __init__(self, *args, **kw):
        wx.PyWindow.__init__(self, *args, **kw)
        self.SetBackgroundColour(wx.RED)
        



class Interpreter(buss.BaseInterpreter):
    results = []
    def init(self):
        """
        1. 请求时间, 2.应答时间, 3. 传输时间, 4.完成时间, 5.备注.
        """
        if hasattr(self, '_request') and self._request:
            self.results.append([self._request, self._response, self._startTrans,
                             self._complete, self._remark])
        self._request = ''
        self._response = ''
        self._startTrans = ''
        self._complete = ''
        self._remark = {}
        
        self._packages = set()
        self._total = 0
        
    def complete(self):
        self.init()
        ctrl = wx.ListCtrl(self.getParent(), style=wx.LC_REPORT)
        x = [u'请求时间', u'应答时间', u'传输时间', u'完成时间', u'备注']
        for i in range(len(x)):
            ctrl.InsertColumn(i, x[i])
        print self.results
        return ctrl
        for result in self.results:
            index = ctrl.InsertStringItem(sys.maxint, result[0])
            ctrl.SetStringItem(index, 1, result[1])
            ctrl.SetStringItem(index, 2, result[2])
            ctrl.SetStringItem(index, 3, result[3])
            ctrl.SetStringItem(index, 4, str(result[4]))
        return ctrl
                
    
    def setCheckPoints(self, resolution, quality):
        self._resolution = resolution
        self._quality = quality
        self._request = self.getTime()
        
    def checkCheckPoints(self, resolution, quality):
        self._remark['xx'] = (resolution == self._resolution)
        self._remark['aa'] = (quality == self._quality)
        self._startTrans = self.getTime()
        
    def setResponse(self, response):
        self._remark['response'] = response
        self._response = self.getTime()
        
    def setImageData(self, total, current):
        self._total = total
        self._packages.add(current)
        if current == total -1 and len(self._packages) == current:
            self._complete = self.getTime()
            self.init()
        
    
            

    
    
__all__ = [Interpreter]